package cn.all;

import java.util.Scanner;

/*
 * 矩阵类
 */

public class Matrix {
	private int rows;
	private int cols;
	private int[][] data;
	
	/*
	 * 获取数组元素
	 */
	public int getelements(int i,int j) {
		int elem;
		elem = data[i][j];
		return elem;
	}
	
	
	/**
	 * @author LYW
	 * 无参构造函数
	 */
	public Matrix() {
		// 
	}
	
	public Matrix(int row,int col) {
		
		
		//给属性赋值
		rows=row;
		cols = col;
		data = new int[rows][cols];
		
		//输出创建成功信息
		System.out.println("成功创建一个"+rows+"行"+cols+"列");
	}
	
	/**
	 * 给矩阵填值
	 */
	public void writeMatrix() {
		//调用scanner类
		Scanner sc= new Scanner(System.in);
		//循环遍历矩阵
		for(int i=0;i<rows;i++) {
			for(int j=0;j<cols;j++) {
				//给矩阵赋值
				//输出信息
				System.out.println("给矩阵第"+i+"行第"+j+"列赋值：");
				data[i][j]=sc.nextInt();
			}
		}
		
	}
	
	
	/**
	 * 输出单个矩阵
	 */
	public void printMatrix() {
		for(int i=0;i<rows;i++) {
			for(int j=0;j<cols;j++) {
				
				System.out.println(data[i][j]+" ");
			
			}
			System.out.println();
		}
	}

	public int getCols() {
		// TODO Auto-generated method stub
		return cols;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int[][] getData() {
		return data;
	}

	public void setData(int[][] data) {
		this.data = data;
	}

	public void setCols(int cols) {
		this.cols = cols;
	}
	
	
	
	
}
